export class Enum {
  private static enums: { [key: string]: any };

  private static getEnumData(){
    if(this.enums){
      return;
    }
    this.enums = window.enums;
    this.enums.projectTypeInt=[
      { value: 0, text: '智能制造' ,deleted:'0'},
      { value: 1, text: '(旧20200219)精益全价值链',deleted:'1' },
      { value: 2, text: '精益营销',deleted:'0' },
      { value: 3, text: '精益研发',deleted:'0' },
      { value: 4, text: '精益人力管理' ,deleted:'0'},
      { value: 5, text: '精益供应链',deleted:'0' },
      { value: 6, text: '精益全价值链',deleted:'0' }
    ];

  }

  /**
   * 获取枚举项目
   * @param enumid 枚举
   * @param flg 1：自动在前面添加全部
   */
  static getEnum(enumid: string, flg: number = 0) {
    let ret = [];
    this.getEnumData();

    if (flg === 1) {
      ret.push({value: '', text: '全部'});
    }

    ret = ret.concat(this.enums[enumid]);

    return ret;
  }

  /**
   * 获取枚举项目(针对deleted字段进行过滤)
   * @param enumid 枚举
   * @param name ：过滤字段
   * @param value ：过滤值
   */
  static getEnumByCon(enumid: string, name: string, value:string) {
    let ret = [];
    this.getEnumData();
    let obj = this.enums[enumid];

    if (name.length>0) {
      for (let idx in obj) {
        let row = obj[idx];
        if (row[name] === value) {
          ret.push(row);
        }
      }
    }
    return ret;
  }

  /**
   * 根据枚举ID和value，返回对应的text
   * @param enumid 枚举
   * @param value 枚举值
   * @return 枚举表示值
   */
  static getEnumText(enumid: string, value: string) {
    this.getEnumData();
    let obj = this.enums[enumid];
    for (let idx in obj) {
      let row = obj[idx];
      if (row.value === value) {
        return row.text;
      }
    }

    return '';
  }

}
